]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
calendar: Use GDateTime for selected-date-changed signal
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Mon, 2 Sep 2019 19:18:54 +0000 (21:18 +0200)
committerFlorian Müllner <florian.muellner@gmail.com>
Wed, 16 Oct 2019 15:26:12 +0000 (15:26 +0000)
Since GObject derived classes can't use JS objects as signal parameters, let's
go native and use GLib.DateTime instead.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559

js/ui/calendar.js
js/ui/dateMenu.js

index 6abc23e6cac51b0b558973e8cc3c3656b5c5e09f..ec89ebf00d66e111e72ccf8e0f3f1c0fa0e784f8 100644 (file)
@@ -373,7 +373,10 @@ var Calendar = class Calendar {
 
         this._selectedDate = date;
         this._update();
-        this.emit('selected-date-changed', new Date(this._selectedDate));
+
+        let datetime = GLib.DateTime.new_from_unix_local(
+            this._selectedDate.getTime() / 1000);
+        this.emit('selected-date-changed', datetime);
     }
 
     updateTimeZone() {
index 9a086de477e3378ad721a446f05dafc8c8e31480..f3da28ff1d331daaa60be046a4e439984cb77d16 100644 (file)
@@ -25,6 +25,10 @@ function _isToday(date) {
            now.getDate() == date.getDate();
 }
 
+function _gDateTimeToDate(datetime) {
+    return new Date(datetime.to_unix() * 1000 + datetime.get_microsecond() / 1000);
+}
+
 var TodayButton = class TodayButton {
     constructor(calendar) {
         // Having the ability to go to the current date if the user is already
@@ -52,10 +56,10 @@ var TodayButton = class TodayButton {
         hbox.add_actor(this._dateLabel);
 
         this._calendar = calendar;
-        this._calendar.connect('selected-date-changed', (calendar, date) => {
+        this._calendar.connect('selected-date-changed', (_calendar, datetime) => {
             // Make the button reactive only if the selected date is not the
             // current date.
-            this.actor.reactive = !_isToday(date);
+            this.actor.reactive = !_isToday(_gDateTimeToDate(datetime));
         });
     }
 
@@ -529,11 +533,11 @@ class DateMenuButton extends PanelMenu.Button {
         bin.add_actor(hbox);
 
         this._calendar = new Calendar.Calendar();
-        this._calendar.connect('selected-date-changed',
-                               (calendar, date) => {
-                                   layout.frozen = !_isToday(date);
-                                   this._messageList.setDate(date);
-                               });
+        this._calendar.connect('selected-date-changed', (_calendar, datetime) => {
+            let date = _gDateTimeToDate(datetime);
+            layout.frozen = !_isToday(date);
+            this._messageList.setDate(date);
+        });
 
         this.menu.connect('open-state-changed', (menu, isOpen) => {
             // Whenever the menu is opened, select today